home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11595 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: doors.informatik.uni-siegen.de!plrunu
  2. From: plrunu@informatik.uni-siegen.de (Runu Knips)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: using template
  5. Date: 15 Mar 1996 12:39:16 GMT
  6. Organization: University of Siegen
  7. Sender: plrunu@doors.informatik.uni-siegen.de (Runu Knips)
  8. Message-ID: <4ibodk$br5@si-nic.hrz.uni-siegen.de>
  9. References: <31415360.2A20@bass.com.my>
  10. NNTP-Posting-Host: doors.informatik.uni-siegen.de
  11.  
  12. In article <31415360.2A20@bass.com.my>, Thomas Chai <jhchai@bass.com.my> writes:
  13. |> include <iostream.h>
  14. |> 
  15. |> template <class T> class STACK {
  16. |>         int stackidx;
  17. |>         T stack[100];
  18. |> public :
  19. |>         STACK() { stackidx = 0; }
  20. |>         void push(T entry) { stack[stackidx++] = entry; }
  21. |>         T pop() { return stack[--stackidx]; }
  22. |> };
  23. |> 
  24. |> main()
  25. |> {
  26. |>         STACK<float> s1;
  27. |> 
  28. |>         s1.push(32.12);
  29. |>         s1.push(1.092);
  30. |>         cout << "pop = " << s1.pop() << "\n";
  31. |>         cout << "pop = " << s1.pop() << "\n";
  32. |>         cout << "pop = " << s1.pop() << "\n";
  33. |> }
  34. |> 
  35. |> 
  36. |> Hi,
  37. |> 
  38. |>     for the example above how do I make use of the
  39. |>     STACK class to push and pop using data type (char *)
  40. |> 
  41. |>         I try using STACK<char *> s1...but the compiler complains
  42.  
  43.  
  44. Ooops, my compilers accept this...
  45.  
  46. Maybe try 'typedef char *string;' and then STACK<string> ?
  47.  
  48. Nevertheless, it seems to be a bug of your compiler if it
  49. didn't accept this. Try g++, for example :*).
  50.  
  51.